package com.gitee.baqkft.code.core.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串工具集
 * @author chenmingcai
 * @date 2018年5月21日 下午2:17:33 
 *
 */

public class StringUtils extends org.apache.commons.codec.binary.StringUtils
{
	/**
	 * 将字符串转换成驼峰命名法: a_bc_de转换成aBcDe
	 * @param text
	 * @return
	 */
	public static String toCamelString(String text)
	{
		if(text == null || "".equals(text))
		{
			return "";
		}
		
		StringBuffer target = new StringBuffer();
		
		Pattern pattern = Pattern.compile("_([a-zA-Z]{1})");
		Matcher matcher = pattern.matcher(text);
		while(matcher.find())
		{
			String letter = matcher.group(1).toUpperCase();
			matcher.appendReplacement(target, letter);
		}
		matcher.appendTail(target);
		return target.toString();
	}
	
	/**
	 * 将名称转换成Pascal命名字符串：ah_bc_de转换成AhBcDe
	 * @param text	名称
	 * @return
	 */
	public static String toPascalString(String text)
	{
		StringBuffer target = new StringBuffer(toCamelString(text));
		if(target.length() > 0)
		{
			Character first = target.charAt(0);
			target.setCharAt(0, Character.toUpperCase(first));
		}
		return target.toString();
	}
}
